package pers.zc.activiti.service.impl;

import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;
import pers.zc.activiti.service.AsyncService;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.Future;

/**
 * @Annotion:
 * @ClassName: AsyncServiceImpl
 * @Author: Lin Fuyuan
 * @Date: 2019/10/11  14:19
 * @Version: 1.0
 */
@Service
@Async
public class AsyncServiceImpl implements AsyncService {


    @Override
    public Future<String> run() {
        try {
            Thread.sleep(5000);
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("线程1执行了"+Thread.currentThread().getName());
        return new AsyncResult<String> ("run");
    }

    @Override
    public Future<String> start1() {
        System.out.println("start1"+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
        try {
            Thread.sleep(5000);
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("start1执行了"+Thread.currentThread().getName());
        return new AsyncResult<String> ("start1");
    }

    @Override
    public Future<String> start2() {
        System.out.println("start2"+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
        try {
            Thread.sleep(5000);
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("start2执行了"+Thread.currentThread().getName());
        return new AsyncResult<String> ("start2");
    }

    @Override
    public Future<String> start3() {
        try {
            Thread.sleep(5000);
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("start3执行了"+Thread.currentThread().getName());
        return new AsyncResult<String> ("start3");
    }
}
